package tech.aistar.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import tech.aistar.entity.Pet;
import tech.aistar.entity.UserInfo;
import tech.aistar.entity.UserLogin;
import tech.aistar.service.*;

@Controller
@RequestMapping("/del")
public class DelUserController {
    @Autowired
    private IPetService petService;
    @Autowired
    private IUserRelationService userRelationService;
    @Autowired
    private ICollectionsService collectionsService;
    @Autowired
    private IUserInfoService userInfoService;
    @Autowired
    private IUserLoginService userLoginService;
    @Autowired
    private IPostService postService;
    @Autowired
    private IPictureService pictureService;

    //删除宠物信息
    @GetMapping("/pet/{pId}")
    public String delPet(@PathVariable("pId") Long pId){
        System.out.println(pId);
        petService.delPet(pId);
        return "redirect:/info/details";
    }

    @PostMapping("/focu/{id}/{userByid}")
    public String delFocu(@PathVariable("id")Integer id,@PathVariable("userByid")Integer userByid){
        userRelationService.delFouc(id,userByid);
        System.out.println("del----------------"+id+userByid);
        //重新后台加载该关注页面
        return "forward:/info/focuson";
    }

    @PostMapping("/goods/{id}/{kindId}")
    public String delGoods(@PathVariable("id")Integer id,@PathVariable("kindId")Integer kindId){
        collectionsService.delGoods(id, kindId);
        System.out.println("del----------------"+id+"   del"+kindId);
        //重新后台加载该关注页面
        return "forward:/info/collect";
    }

    @PostMapping("/collpost/{id}/{kindId}")
    public String delcolls(@PathVariable("id")Integer id,@PathVariable("kindId")Integer kindId){
        collectionsService.delPosts(id,kindId);
        System.out.println("del----------------"+id+"   del"+kindId);
        //重新后台加载该关注页面
        return "forward:/info/collect";
    }

    //用户的主键id
    @PostMapping("/email/{id}")
    public @ResponseBody Boolean delEmail(@PathVariable("id")Integer id){
        userInfoService.addEmail(null,id);
        UserInfo userInfo = userInfoService.findById(id);
        if(null==userInfo.getuEmail()) {
            System.out.println("del------email----------" + id + "   del");
            return true;
        }
        return false;
    }

    //用户的账号id
    @PostMapping("/numder/{userId}")
    public  @ResponseBody Boolean delNumder(@PathVariable("userId")String userId){
        userLoginService.addCard(null,null,userId);
        //查找一下他是否已被删除
        UserLogin userLogin = userLoginService.findByUserId(userId);
        if(null ==userLogin.getNumder()) {
            System.out.println("del------numder----------" + userId + "   del");
            //重新后台加载该关注页面
            return true;
        }
        return false;
    }

    //删除帖子
    @PostMapping("/post/{postId}")
    public String delPosts(@PathVariable("postId")Integer postId){
        postService.delPost(postId);
        System.out.println("del-------kkkk---------"+postId+"   del");
        //重新后台加载该关注页面
        return "forward:/info/details";
    }

    //删除动态
    @PostMapping("/pic/{picId}")
    public String delPic(@PathVariable("picId")Integer picId){
        pictureService.delById(picId);
        System.out.println("涮出啊-------"+picId);
        //重新后台加载该关注页面
        return "forward:/info/details";
    }
}
